package com.cloud.code.leetcode;

public class Demo3 {

    public static void main(String[] args) {
        maxSlidingWindow(new int[]{1,3,-1,-3,5,3,6,7},3);
    }

    public static int[] maxSlidingWindow(int[] nums, int k) {

        int max = 0;
        int[] num = new int[nums.length - k];
        if (nums.length == k) {
            return nums;
        }

        for (int i = 0; i < k; i++) {
            max = max + nums[i];
        }
        num[0] = max;
        int i = 0;
        int j = i+k;
        while (j < nums.length){

            int tem = max-nums[i]+nums[j];
            if(max >= tem){
                num[i+1] = max;
            }else {
                num[i+1] = tem;
                max = tem;
            }

            i++;
            j++;
        }

        return num;

    }
}
